<?php
declare (strict_types = 1);

namespace app\admin\controller;

class Pages extends AdminBase
{
    protected function initialize()
    {
        parent::initialize();
        $this->model = new \app\common\model\Pages;
        $this->validate = new \app\common\validate\Pages;
        $this->order = 'id desc';
    }
    // 设置搜索条件
    protected function searchConditionHandle(&$where)
    {
        $search = $this->request->param('search',null);
        if($search) {
            $search = json_decode($search, true);
            if(is_array($search) && sizeof($search) > 0) {
                ((array_key_exists('title', $search) && !empty($search['title'])) && $where[] = ['title','like', '%'.$search['title'].'%']);
                if(array_key_exists('field', $search) && !empty($search['field'])){
                    ((array_key_exists('keyword', $search) && !empty($search['keyword'])) && $where[] = [$search['field'], 'like', '%'.$search['keyword'].'%']);
                } else {
                    ((array_key_exists('keyword', $search) && !empty($search['keyword'])) && $where[] = ['title|custom_path','like', '%'.$search['keyword'].'%']);
                }
            }
        }
    }
}
